<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<jsp:include page="../../header.jsp" />
<div class="content-header">
    <h2 class="content-title">员工管理</h2>
    <div class="action-buttons">
        <a href="employee?action=new" class="btn btn-primary">
            <i class="icon-add"></i> 添加新员工
        </a>
    </div>
</div>

<div class="search-container">
    <form action="employee" method="get" class="search-form">
        <input type="hidden" name="action" value="search">
        <input type="text" name="keyword" placeholder="输入员工姓名或职位..." value="${param.keyword}">
        <select name="departmentId">
            <option value="">所有部门</option>
            <c:forEach var="dept" items="${departments}">
                <option value="${dept.id}" ${param.departmentId == dept.id ? 'selected' : ''}>
                        ${dept.name}
                </option>
            </c:forEach>
        </select>
        <button type="submit" class="btn btn-search">
            <i class="icon-search"></i> 搜索
        </button>
    </form>
</div>

<div class="card">
    <div class="card-body">
        <table class="data-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>性别</th>
                <th>职位</th>
                <th>部门</th>
                <th>入职日期</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="emp" items="${employees}">
                <tr>
                    <td>${emp.id}</td>
                    <td>
                        <div class="employee-info">
                            <div class="avatar">
                                <c:choose>
                                    <c:when test="${emp.gender == '男'}">
                                        <i class="icon-male"></i>
                                    </c:when>
                                    <c:otherwise>
                                        <i class="icon-female"></i>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <div class="details">
                                <strong>${emp.name}</strong>
                                <div class="contact">${emp.phone}</div>
                            </div>
                        </div>
                    </td>
                    <td>${emp.gender}</td>
                    <td>${emp.position}</td>
                    <td>${emp.departmentName}</td>
                    <td>${emp.formattedHireDate}</td>
                    <td>
                        <span class="status active">在职</span>
                    </td>
                    <td>
                        <div class="actions">
                            <a href="employee?action=edit&id=${emp.id}" class="btn-action btn-edit" title="编辑">
                                <i class="icon-edit"></i>
                            </a>
                            <a href="employee?action=delete&id=${emp.id}"
                               class="btn-action btn-delete" title="删除"
                               onclick="return confirm('确定要删除该员工吗？')">
                                <i class="icon-delete"></i>
                            </a>
                            <a href="salary?action=new&employeeId=${emp.id}" class="btn-action btn-salary" title="发工资">
                                <i class="icon-salary"></i>
                            </a>
                        </div>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>

        <div class="pagination">
            <c:if test="${currentPage > 1}">
                <a href="employee?page=${currentPage-1}" class="page-link">&laquo; 上一页</a>
            </c:if>

            <c:forEach begin="1" end="${totalPages}" var="i">
                <c:choose>
                    <c:when test="${i == currentPage}">
                        <span class="page-link current">${i}</span>
                    </c:when>
                    <c:otherwise>
                        <a href="employee?page=${i}" class="page-link">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>

            <c:if test="${currentPage < totalPages}">
                <a href="employee?page=${currentPage+1}" class="page-link">下一页 &raquo;</a>
            </c:if>

            <span class="page-info">共 ${totalItems} 条记录</span>
        </div>
    </div>
</div>
<jsp:include page="../../footer.jsp" />